package com.qinghuan.threads.chapterOne;

import lombok.SneakyThrows;

/**
 * @Author: dubao
 * @Date: 2022/5/16 20:29
 * @Description:
 */
public class Test1_3_test {

    private static volatile Object resourceA = new Object();

    public static void main(String[] args) throws InterruptedException {

        Thread threadA = new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                synchronized (resourceA) {
                    System.out.println("begin threadA---");
                    resourceA.wait();
                    System.out.println("end threadA---");
                }
            }
        });

        Thread threadB = new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                synchronized (resourceA) {
                    System.out.println("begin threadB---");
                    resourceA.wait();
                    System.out.println("end threadB---");
                }
            }
        });

        Thread threadC = new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                synchronized (resourceA) {
                    System.out.println("begin threadC---");
                    resourceA.wait();
                    System.out.println("end threadC---");
                }
            }
        });

        Thread threadD = new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                synchronized (resourceA) {
                    System.out.println("begin threadD---");
                    resourceA.wait();
                    System.out.println("end threadD---");
                }
            }
        });

        Thread threadE = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (resourceA) {
                    System.out.println("begin threadE---");
                    resourceA.notify();
                }
            }
        });

        threadA.start();
        threadB.start();
        threadC.start();
        threadD.start();
        Thread.sleep(1000);
        threadE.start();

        threadA.join();
        threadB.join();
        threadC.join();
        threadD.join();
        threadE.join();

    }

}
